using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterController : MonoBehaviour
{
    // Start is called before the first frame update

    //public float speed;
    public LayerMask platformMask;
    private bool onGround;

    public float jumpHeight = 2f;
    public float gravity = -25f;
    public void Move(Vector3 velocity)
    {
       
        transform.Translate(velocity*Time.deltaTime);
    }

    public void checkGround()
    {
        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down, 2f, platformMask);
        if (hit.collider != null)
        {
            onGround = true;
        }
        else
        {
            onGround = false;
        }
    }

    public void jump()
    {
        GetComponent<Rigidbody2D>().velocity = new Vector3(0f, Mathf.Sqrt( jumpHeight * -gravity), 0f);

    }

    public bool isGrounded()
    {
        return onGround;
    }
}
